package yawning.mew.gui.characters.attributes;

import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextPane;

import yawning.mew.gui.tools.CharacterDataSource;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;

@SuppressWarnings("serial")
public class MagicAttributes extends JPanel {
	private CharacterDataSource source; 
	private JSpinner spnHaste;
	private JSpinner spnHit;
	private JSpinner spnCrit;
	/**
	 * Create the panel.
	 */
	public MagicAttributes(CharacterDataSource source) {
		this.source = source;
		setLayout(null);
		JTextPane textPane = new JTextPane();
		textPane.setText("Crit:");
		textPane.setEditable(false);
		textPane.setBounds(10, 110, 84, 22);
		add(textPane);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setText("Hit:");
		textPane_1.setEditable(false);
		textPane_1.setBounds(10, 77, 84, 22);
		add(textPane_1);
		
		JTextPane textPane_2 = new JTextPane();
		textPane_2.setText("Haste:");
		textPane_2.setEditable(false);
		textPane_2.setBounds(10, 44, 84, 22);
		add(textPane_2);
		
		JTextPane txtpnSpellPower = new JTextPane();
		txtpnSpellPower.setText("Spell Power:");
		txtpnSpellPower.setEditable(false);
		txtpnSpellPower.setBounds(10, 11, 84, 22);
		add(txtpnSpellPower);
		
		JSpinner spnSpellPower = new JSpinner();
		spnSpellPower.setToolTipText("Base attack power");
		spnSpellPower.setEnabled(false);
		spnSpellPower.setBounds(104, 13, 84, 20);
		add(spnSpellPower);
		
		spnHaste = new JSpinner();
		spnHaste.setToolTipText("Haste rating");
		spnHaste.setBounds(104, 46, 84, 20);
		add(spnHaste);
		
		spnHit = new JSpinner();
		spnHit.setToolTipText("Hit rating");
		spnHit.setBounds(104, 79, 84, 20);
		add(spnHit);
		
		spnCrit = new JSpinner();
		spnCrit.setToolTipText("Crit rating");
		spnCrit.setBounds(104, 112, 84, 20);
		add(spnCrit);
		initDataBindings();

	}
	protected void initDataBindings() {
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty = BeanProperty.create("toon.rating_Haste");
		BeanProperty<JSpinner, Object> jSpinnerBeanProperty_1 = BeanProperty.create("value");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty, spnHaste, jSpinnerBeanProperty_1, "spellHaste");
		autoBinding.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_1 = BeanProperty.create("toon.rating_Hit");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_1, spnHit, jSpinnerBeanProperty_1, "spellHit");
		autoBinding_1.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_2 = BeanProperty.create("toon.rating_Crit");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_2, spnCrit, jSpinnerBeanProperty_1, "spellCrit");
		autoBinding_2.bind();
	}
}
